package com.woshua.gifmodel.core;

import android.content.Context;
import android.net.Uri;
import android.os.AsyncTask;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/*
* gif文件的加载
* */
public class GifDecoder {

   private static GifDecoder instance=new GifDecoder();

   private static Context context;

   private GifDecoder(){}

   public static GifDecoder with(Context c)
   {
       context=c;

       return instance;
   }

   /*
   * load gif file inputstream
   * */
   public GifDrawer load(InputStream inputStream)
   {
        GifDrawer drawer=new GifDrawer();
        drawer.setInputStream(inputStream);

        return drawer;
   }

   /*
   * load gif file
   * */
   public GifDrawer load(File file)
   {
       InputStream inputStream=null;
       try {
           inputStream=new FileInputStream(file);
       } catch (FileNotFoundException e) {
           e.printStackTrace();
       }
       return load(inputStream);
   }

   /*
   * load gif uri
   * */
   public GifDrawer load(Uri uri)
   {
       InputStream inputStream=null;

       try {
           inputStream=context.getContentResolver().openInputStream(uri);
       } catch (FileNotFoundException e) {
           e.printStackTrace();
       }
       return load(inputStream);
   }
}
